package cd.cdyb.sms.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Author: lilin
 * @CreateTime: 2023-07-28  09:38
 * @Description: TODO
 */

@Configuration
public class RabbitConfig {

    @Autowired
    private ConnectionFactory connectionFactory;


    @Value("${mq.queue}")
    private String queue;

    @Value("${mq.routeKey}")
    private String routeKey;

    @Value("${mq.exchange}")
    private String exchange;

    @Value("${mq.message_queue}")
    private String message_queue;

    @Value("${mq.message_routeKey}")
    private String message_routeKey;


    @Bean
    public RabbitTemplate rabbitTemplate() {
        return new RabbitTemplate(connectionFactory);
    }

    @Bean
    public DirectExchange smsDirectExchange() {
        return new DirectExchange(exchange, true, false);
    }

    @Bean
    public Queue smsDirectQueue() {
        return new Queue(queue, true);
    }

    @Bean
    public Queue smsSendDirectQueue() {
        return new Queue(message_queue, true);
    }


    @Bean
    public Binding smsDirectBinding() {
        return BindingBuilder.bind(smsDirectQueue()).to(smsDirectExchange()).with(routeKey);
    }

    @Bean
    public Binding smsSendDirectBinding() {
        return BindingBuilder.bind(smsSendDirectQueue()).to(smsDirectExchange()).with(message_routeKey);
    }

}

